﻿@model QuanLyGiaoVuUI.Models.GiangVienClient.DeTaiGiangVienClientViewModel
@{
    ViewBag.Title = "DeTai";
    Layout = "~/Views/Shared/_blueWhaleLayout.cshtml";
}
<style>
    table.display {
        text-align:left;
    }
</style>
<div id="gv-main-wrapper">
    @{Html.RenderPartial("QuanLyDeTaiMenuPartial");}

    <div id="main" class="grid_10 gvclientmain">
        <!--  start page-heading -->        
        <div id="page-heading" class="box round first grid">
            <h2>Đăng ký đề Tài Năm Học @Model.namHoc.Nam1 - @Model.namHoc.Nam2</h2>
            <!-- end page-heading -->            
            <div id="gvclientmaincontent" class="block">                                
                <style>
                    .chitietdetai td {
                        padding: 10px;
                    }
                </style>
                <div style="overflow: auto;max-height: 500px;">
                    <div><input type="button" id="themDeTai" value="Thêm đề tài"/></div>
                    <table class="data display datatable">
                        <tr>
                            <th class="sorting">STT</th>
                            <th class="sorting">Tên Đề Tài</th>
                            <th class="sorting">GVHD1</th>
                            <th class="sorting">GVHD2</th>
                            <th class="sorting">Trạng thái</th>
                            <th class="sorting">Đủ ĐK Khóa Luận</th>
                            <th class="sorting">Mô Tả</th>
                            <th class="sorting"></th>
                        </tr>
                        @{var count = 0; var stt = 1;}
                        @foreach (var detai in Model.deTaiGiangVien)
                        {
                            <tr class="gradeA @(++count % 2 == 0 ? "even" : "odd")">
                                <td class="odd gradeX">@(stt++)</td>
                                <td class="odd gradeX">@detai.TenDeTai</td>
                                <td class="odd gradeX">@detai.GiangVien1.HoTenGV</td>
                                <td class="odd gradeX">@detai.GiangVien2.HoTenGV</td>
                                <td class="odd gradeX">@(!detai.DatYeuCau?"Chờ duyệt":"Đã duyệt")</td>
                                @if (detai.KhoaLuanTotNghiep > 0)
                                {
                                    <td class="odd gradeX">Đã XN</td>   
                                }
                                else
                                {
                                    <td class="odd gradeX">Chưa XN</td>
                                }
                                <td class="odd gradeX">@Html.Raw(detai.MoTa)</td>
                                <td class="odd gradeX">
                                    <a class="suadt" rel="@detai.MaDeTai">[Sửa]</a>
                                    <a class="xoadt" rel="@detai.MaDeTai">[Xoá]</a>
                                </td>
                            </tr>
                        }
                    </table>
                </div>
            </div>            
        </div>
    </div>

    <div class="clear">&nbsp;</div>
    <div id="suaDeTaiDialog"></div>
    <div id="themDeTaiDialog"></div>
</div>
@*<script type="text/javascript">
    var editor = CKEDITOR.replace('MoTa');
</script>*@


<script>
    $(document).ready(function () {        
        $('.xoadt').click(function () {
            var madetai = $(this).attr("rel");
            //alert(madetai);
            var r=confirm("Bạn có muốn xóa?")
            if (r != true) {
                return;
            }
            if (madetai == null || madetai == "") {
                return;
            }
            else {
                //alert(madetai);
                $.post("/TienDoDeTai/XoaDeTai", { MaDeTai: madetai }, function (data) {
                    //if (data.success == true) {
                    //    window.location = "/TienDoDeTai/Detai";
                    //}
                    //else {
                        
                    //}
                    //alert(data.message);
                    ThongBao(data);
                });
            }
        });
        $("#suaDeTaiDialog").dialog({
            autoOpen: false, modal: true, width: 800, height: "auto", title: "Cập nhật đề tài",
            //buttons: {
            //    "": function () {
            //        $("#btnSuaDeTai").click();
            //    },
            //    "Hủy": function () {
            //        $("#suaTaiDialog").dialog("close");
            //    }
            //}
        });
        $("#themDeTaiDialog").dialog({
            autoOpen: false, modal: true, width: 800, height: "auto", title: "Thêm đề tài",
            //buttons: {
            //    "": function () {
            //        $("#btnSuaDeTai").click();
            //    },
            //    "Hủy": function () {
            //        $("#suaTaiDialog").dialog("close");
            //    }
            //}
        });
        $('#themDeTai').click(function () {
            $("#themDeTaiDialog").load('/TienDoDeTai/ThemDeTai/');
            $("#themDeTaiDialog").dialog("open");
        });
        $('.suadt').click(function () {
            var madetai = $(this).attr("rel");
            //alert(madetai);
            $("#madetaidk").attr("value", madetai);
            $("#suaDeTaiDialog").load('/TienDoDeTai/SuaDeTai/' + madetai);
            $("#suaDeTaiDialog").dialog("open");
        });
    });
    function reloadPage() {
        window.location = "/TienDoDeTai/DeTai/";
    }
    function ThongBao(data) {
        if (data.success) {
            ToastManager.showSuccessToast(data.message);
            setTimeout(function () {
                reloadPage();
            }, 2000);
        }
        else {
            ToastManager.showStickyWarningToast(data.message);
        }
    }
</script>
